<?php
/**
 * @desc
 * @date 2019-07-13
 * @author ljm
 */
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class DownloadCat extends Model
{
    /**
     * @var string
     */
    public $table = 'download_cat';
    /**
     * @var
     */
    public $downLoadCatModel;
    /**
     * @var
     */
    public $id;
    public $pid;
    public $title;
    public $status;
    public $description;
    public $psort;
    public $created_at;
    public $updated_at;

    /**
     * DownloadCat constructor.
     */
    public function __construct()
    {
        $this->downLoadCatModel = DB::table($this->table);
        $this->id='id';
        $this->pid='pid';
        $this->title='title';
        $this->status='status';
        $this->description='description';
        $this->psort='psort';
        $this->created_at='created_at';
        $this->updated_at='updated_at';
    }

    /**
     *
     */
    public function getList($params){
        $data=[];
        if($params['getfields']){
            $data['total'] = $this->downLoadCatModel->where($params['where'])->count();
            $data['row'] = $this->downLoadCatModel->where($params['where'])->skip($params['page'])->take($params['pagesize'])->get($params['field']);

        }else{
            $data['row'] = $this->downLoadCatModel->where($params['where'])->orderByDesc($params['order'])->get($params['field']);
        }
        return $data;
    }

    /**
     * @param $params
     * @return bool
     */
    public function saveAdd($params){
        $data=[
            $this->pid   => $params['pid'],
            $this->title => $params['title'],
            $this->description => $params['description'],
            $this->psort       => $params['psort'],
            $this->status      =>$params['status'],
            $this->created_at  =>date('Y-m-d H:i:s',time()),
            $this->updated_at  =>date('Y-m-d H:i:s',time()),
        ];
        $rs = $this->downLoadCatModel->insert($data);
        return $rs;
    }
}
